<template>
    <div class="room-manage">
        <div class="personal-manage-title">密码管理</div>
        <div class="password-set-manage">
            <div style="width: 400px;padding: 20px 0 0 40px">
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="当前密码">
                        <el-input type="password" size="small" v-model="form.oldPwd"></el-input>
                    </el-form-item>
                    <el-form-item label="新密码">
                        <el-input type="password" size="small" v-model="form.newPwd"></el-input>
                    </el-form-item>
                    <el-form-item label="确认密码">
                        <el-input type="password" size="small" v-model="form.confirmPwd"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" size="small" @click="onSubmit">保存</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="page-padding"></div>
    </div>
</template>

<script type="text/ecmascript-6">
// 1、一页20条数据
// 2、勾选框和下拉框和输入框做判断
export default {
    data: function () {
        return {
            form: {
                oldPwd: '',
                newPwd: '',
                confirmPwd: ''
            }
        }
    },
    components: {
    },
    mounted () {
    },
    watch: {
    },
    methods: {
        onSubmit () {
            if (this.form.oldPwd === '') {
                this.$message({
                    message: '当前密码不能为空',
                    type: 'warning'
                })
                return
            }
            if (this.form.newPwd === '') {
                this.$message({
                    message: '新密码不能为空',
                    type: 'warning'
                })
                return
            }
            if (this.form.newPwd === this.form.oldPwd) {
                this.$message({
                    message: '新旧密码不能相同',
                    type: 'warning'
                })
                return
            }
            if (this.form.newPwd !== this.form.confirmPwd) {
                this.$message({
                    message: '确认新密码必须与新密码一致',
                    type: 'warning'
                })
                return
            }
            this.$http
                .post(
                    this.$store.state.IP + '/system/editPassWord',
                    {
                        data: {
                            oldPwd: this.form.oldPwd,
                            newPwd: this.form.newPwd,
                            confirmPwd: this.form.confirmPwd,
                            userId: this.$route.query.staffID
                        }
                    },
                    {
                        emulateJSON: false
                    }
                )
                .then(
                    response => {
                        console.log(
                            '-------------------------------------------'
                        )
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            console.log('调用修改密码成功')
                            console.log(response.data)
                            this.form.oldPwd = ''
                            this.form.newPwd = ''
                            this.form.confirmPwd = ''
                            this.$message({
                                message: '修改密码成功',
                                type: 'success'
                            })
                            this.getAndroid()
                            //						this.$router.push('mainPage')
                        }
                        if (response.ret !== '0') {
                            //						this.$message.error('修改密码失败')
                            console.log('调用修改密码失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
.room-manage
    width: 100%
    background #fff
    min-height calc(100vh - 65px)

    .personal-manage-title
        width: 100%
        height: 64px
        line-height: 64px
        color: #000
        font-size: 18px
        background #f1f0f5
        position: relative

    .password-set-manage
        width: 100%
        height: 270px
        background: #fff

    .page-padding
        width: 100%
        height: 150px
        background: #fff
</style>
